package com.github.McPlugin.event;

//import com.Hulk.minecraft.GUI.TaskGUI;


import com.github.McPlugin.main;
import com.github.McPlugin.util.Task.PlayerTasks;
import com.github.McPlugin.util.Task.Task;
import com.github.McPlugin.util.Task.TasksTool;
import com.github.McPlugin.vexview.MyGui;
import com.google.gson.Gson;
import lk.vexview.api.VexViewAPI;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;


public class EntitysEvent implements Listener {

    @EventHandler
    public void PlayerDamage(EntityDamageByEntityEvent event) {

        Entity damager = event.getDamager();

        main.plugin.getLogger().info(damager.getName() + "造成了伤害事件");

        Gson g = new Gson();
        String s = g.toJson(EntityType.PLAYER);
        //EntityType e =
        //event.getDamager().sendMessage("tostring " + EntityType.PLAYER.toString());
        //event.getDamager().sendMessage("gson " + g.fromJson(s,EntityType.class));
        if (damager.getType() == g.fromJson(s, EntityType.class)) {
            if (damager.isOp()) {
                event.setDamage(1000);
                //damager.sendMessage(damager.getName() + "对" + event.getEntity().getName() + "造成了" + event.getDamage() + "伤害");
                //damager.sendMessage(String.valueOf(event.getEntity().getEntityId()));
            } else {
                //event.getEntity().getName()
                event.setDamage(10);
                //damager.sendMessage(damager.getName() + "造成了" + event.getDamage() + "伤害");

            }
        }
    }

    @EventHandler
    public void PlayerTeleport(EntityDamageByEntityEvent event) {
        Entity damager = event.getDamager();
        if (damager instanceof Player) {
            Entity entity = event.getEntity();
            //String type = "EntityType.PLAYER";
            Gson g = new Gson();
            String type = g.toJson(EntityType.PLAYER);
            if (entity.getType() == g.fromJson(type, EntityType.class) && entity.getName().equalsIgnoreCase("传送点")) {

                VexViewAPI.openGui((Player)damager,MyGui.transferGui());

            }

            if (entity.getType() == g.fromJson(type, EntityType.class) && entity.getName().equalsIgnoreCase("签到点")) {
                Player player = (Player) event.getDamager();
                VexViewAPI.openGui(player, MyGui.loginGui(player));
            }


            if (entity.getType() == g.fromJson(type, EntityType.class) && entity.getName().equalsIgnoreCase("任务点")) {
                Player player = (Player) event.getDamager();
                VexViewAPI.openGui(player, MyGui.tasksGui(player));

                for (PlayerTasks tas : TasksTool.list_tasks) {
                    if (tas.getPlayer() == player) {
                        for (Task ta : tas.getList_task()) {
                            player.sendMessage("你已接到了" + ta.getTaskName() + "的任务");
                            //event.getPlayer().sendMessage("任务描述: " + ta.getTaskDescription());
                            for (Object key : ta.getTasks().keySet()) {
                                player.sendMessage("任务要求： " + key + "  " + ta.getTasks().get(key).toString());
                            }

                        }

                    }
                }
            }

            if (entity.getType() == g.fromJson(type, EntityType.class) && entity.getName().equalsIgnoreCase("商店")){
                Player player = (Player) event.getDamager();
                MyGui.shopInventory(player);
            }
        }
    }

    @EventHandler
    public void TasksDeal(EntityDamageByEntityEvent event) {
        TasksTool.TaskEvent(event);
    }
}
